<template>
	<view class="bankpay">
		
		<view class="top">
			<view class="search">
				<searchCom @searchClick="searchFun"></searchCom>
			</view>
			<view class="dealtype dealtype1">
				<contentSw :swlist="conSwlist" @conswitch="conswitch"></contentSw>
			</view>
		</view>
		<scroll-view class="list" @scrolltolower="getYsflist">
			<paylistCom :paylistArr="paylist"></paylistCom>
		</scroll-view>
	</view>
</template>

<script>
	import { ysflist } from '../../api/index.js'
	import paylistCom from '../../components/bankpay/paylistCom.vue'
	import contentSw from '../../components/workbench/contentSw.vue'
	import noData from '../../components/data/nodata.vue'
	import searchCom from '../../components/search/searchCom.vue'
	export default {
		data() {
			return {
				conSwlist:[{name:'全部'},{name:'审核中'},{name:'审核失败'},{name:'审核通过'}],
				searchVal:'',
				dealtype1index:0,
				paylist:[],
				page:1,
				limit:20
			}
		},
		onLoad:function(){
			this.getYsflist(true);
		},
		methods: {
			navDetail:function(id,type){
				uni.navigateTo({
					url: '../paydetail/paydetail?id='+id+'&type='+type
				});
			},
			conswitch:function(data){
				this.dealtype1index = data.index;
				this.isLoad = false;
				this.isAll = false;
				this.page = 1;
				this.getYsflist(true)
			},
			getYsflist:function(isSw){
				let that = this;
				let statusObj = {
					'0':'-1',//全部
					'1':'0',//审核中
					'2':'1',//审核通过
					'3':'2' //审核失败
				};
				if(that.isLoad || that.isAll){ //假如之前的请求未完成或者列表数据已经全部加载完毕，则返回空
					console.log("请求未完成或者列表数据已经全部加载完毕")
					return ;
				}
				that.isLoad = true;
				
				ysflist({
					search:that.searchVal,
					status:statusObj[that.dealtype1index],
					page:that.page,
					limit:that.limit
				}).then((res) => {
					console.log(res)
					if(res.code == 0){
						if(isSw === true){//判断是否重新加载数据
							that.paylist = that.deallist(res.data);
						}else{
							that.paylist = that.paylist.concat(that.deallist(res.data));
						}
						
						that.page += 1;
						that.isLoad = false;
						if(res.data.length < that.limit){
							that.isAll = true;
						}
					}else{
						console.log(res)
						that.isLoad = false;
						that.isAll = false;
					}
				}).catch((e) => {
					console.log(e)
				})
			},
			deallist:function(data){
				let list = data.map((item,index,arr)=>{
					let statusTextObj = {
						'-1':'未申请',
						'0':'审核中',
						'1':'审核通过',
						'2':'审核失败'
					}
					return {
						shop_name:item.shop_name, //门店名
						id:item.id, //门店id
						uid:item.uid, //商户id
						merchant_id:item.merchant_id, //银联商户号
						status:item.audit_status, //审核状态:-1未申请,0-未审核,1-审核通过,2-审核失败
						statusText: statusTextObj[item.status]
					};
				});
				return list;
			},
			searchFun:function(data){
				this.searchVal = data.searchComval;
				this.isLoad = false;
				this.isAll = false;
				this.page = 1;
				this.getYsflist(true);
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '../bankupload/bankupload?type=0'
			});
		},
		components:{
			paylistCom,
			searchCom,
			noData,
			contentSw
		}
	}
</script>

<style lang="scss" scoped>
	.bankpay{
		font-size: $uni-font-size-base;
		background-color: #F5F5F5;
		height: 100%;
		position: relative;
		.top{
			position: absolute;
			left: 0;
			right: 0;
			top: 0;
			.dealtype{
				background-color: #FFFFFF;
			}
		}
		
		.list{
			padding: 30rpx;
			box-sizing: border-box;
			height: 100%;
			padding-top: 27%;
		}
	}
</style>